import pandas as pd
from openpyxl import load_workbook


def jximport(jx_path, tax_path):
    jxfp = pd.read_excel(jx_path, sheet_name=0, skiprows=2, dtype='str')
    print(jxfp)
    with pd.ExcelWriter(tax_path, engine='openpyxl', mode='a', if_sheet_exists='replace') as writer:
        book = load_workbook(tax_path)
        writer.book = book  # 读取excel
        writer.sheets = dict((ws.title, ws) for ws in book.worksheets)  # 复制excel的所有表
        jxfp.to_excel(writer, sheet_name='基础表3', startrow=2, index=None)


def get_max_row(sheet):
    i = sheet.max_row
    real_max_row = 0
    while i > 0:
        row_dict = {i.value for i in sheet[i]}
        if row_dict == {None}:
            i = i-1
        else:
            real_max_row = i
            break

    return real_max_row
